Ext.define('appmod.controller.resources.UnloadModules', {
    extend: 'Ext.app.Controller',

	models: [
		'resources.Module'
	],
	
    stores: [
		'resources.UnloadedModules'
	],
    

    refs: [
		{ref: 'modulesList',selector:'moduledashboard gridpanel[region=center]'},
		{ref: 'unloadedModuleList',selector:'unloadmodulelist'}
	],

    views: [
    ],
	

    init: function() {

    	this.control({
			

			'window button[action=loadUnloadedModule]': {
			    click:this.loadUnloadedModule
			}			

								
    	});

    },
	

	/**
	 * defined and binding store --
	 */
	onLaunch:function() {


	},

	
	loadUnloadedModule:function() {
		
		var me = this;

		var unloadedModuleList = me.getUnloadedModuleList();
		var selModel = unloadedModuleList.getSelectionModel();
		var recs = selModel.getSelection();		

		if (recs.length == 0) {
			Ext.MessageBox.show({
        		title: "提示",
        		msg: '请先至少选择一个模块',
        		buttons: Ext.MessageBox.OK,
        		icon: Ext.MessageBox.WARNING
       		});
			return ;
		}
		
		// --- select resource --
		var jsonObj = [];
		for (var i = 0 ; i < recs.length ; i++) {
			jsonObj.push(recs[i].getId());
		}

		// --- update record using ajax
		try {

			Ext.Ajax.request({
				url: '../../data/resource/resources/submit_loadUnloadedModules.json',
				method:'post',
				params:{
					'jsonData':Ext.encode(jsonObj)
				},
				success: function(response, opts) {
					
					var loaededModList = me.getModulesList();
					loaededModList.getStore().load();

					var listView = me.getUnloadedModuleList();
					// --- update load ---
					listView.getStore().load();
										 
     				var obj = Ext.decode(response.responseText);
					 
					 // --- popup message ---
					Ext.MessageBox.show({
        				title: "提示",
        				msg: obj.msg,
        				buttons: Ext.MessageBox.OK,
        				icon: Ext.MessageBox.WARNING
       				});
					
					// --- reload ---

				},
				failure: function(response, opts) {
				
				}
			});

			
		} catch (e) {
			alert(e);
		}	
		




	}
	


	
});